package com.woniuxy.qiantai.interceptors;

import    com.woniuxy.qiantai.entity.User;
import com.woniuxy.qiantai.utils.CookieUtils;
import com.woniuxy.qiantai.utils.JwtUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;


public class LoginInterceptor implements HandlerInterceptor {

  /*  @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("拦截");

        String userTokenFromCookie = CookieUtils.getUserTokenFromCookie(request);

        System.out.println("userTokenFromCookie:" + userTokenFromCookie);

        if (StringUtils.isEmpty(userTokenFromCookie)) {

            request.getRequestDispatcher("/login.html").forward(request, response);

            return false;
        }
        //从userToken中解析出用户名
    *//*    String accountFromToken = "";
        try {
            accountFromToken = JwtUtils.getAccount(userTokenFromCookie);
        } catch (Exception e) {
            System.out.println("token解析出错");
            request.getRequestDispatcher("/login.html").forward(request, response);
            return false;
        }*//*
        System.out.println("拦截器放行");
        return true;

    }*/
}
